package com.zhimeng.personal.adapters;

import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.zhimeng.personal.R;
import com.zhimeng.personal.models.Workinfo;

import java.util.List;

/**
 * Created by sunzhimeng on 16/4/6.
 */
public class WorkinfoAdapter extends RecyclerView.Adapter<WorkinfoAdapter.ViewHolder> {

    private List<Workinfo> workinfos;

    public WorkinfoAdapter(List<Workinfo> ws){
        this.workinfos = ws;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder{
        public CardView cardView;
        public TextView companyTv, periodTv, timeTv;
        public ImageView companyIcon;
    
        public ViewHolder(View v) {
            super(v);
            cardView = (CardView)v.findViewById(R.id.card_view);
            companyTv = (TextView)v.findViewById(R.id.info_text);
            periodTv = (TextView)v.findViewById(R.id.period);
            timeTv = (TextView)v.findViewById(R.id.time);
            companyIcon = (ImageView)v.findViewById(R.id.company_icon);
        }
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        Workinfo w = workinfos.get(position);
        holder.companyTv.setText(w.getCompany());
        holder.periodTv.setText(w.getPeriod());
        holder.timeTv.setText(w.getDuration());

        ImageLoader imageLoader = ImageLoader.getInstance();
        if (!w.getHeadImage().equals(""))
            imageLoader.displayImage(w.getHeadImage(), holder.companyIcon);
    }

    @Override
    public int getItemCount() {
        return workinfos.size();
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.workinfo_item, parent, false);
        ViewHolder vh = new ViewHolder(v);
        return vh;
    }


}
